UIPDIR=/home/fanl/Engenharia/Banco_de_Dados/Libraries/uip

CC=arm-elf-gcc
OBJCOPY=arm-elf-objcopy
OBJDUMP=arm-elf-objdump
LDSCRIPT=ldscript.ld
TARGET=SELivre-ethernet-httpd

LINKER_FLAGS=-mthumb -nostartfiles -Xlinker -o${TARGET}.elf -Xlinker -M -Xlinker -Map=${TARGET}.map

DEBUG=-g
OPTIM=-O1


CFLAGS= \
		$(DEBUG) \
		$(OPTIM) \
		-T$(LDSCRIPT) \
		-I /usr/local/arm-elf/include/ \
		-I . \
		-I ./httpd/ \
		-I $(UIPDIR)/
		-mcpu=arm7tdmi \
		-fomit-frame-pointer \
		-mthumb-interwork
										
THUMB_SOURCE= \
		main.c \
		syscalls.c \
		./uart/uart.c \
		./timer/timer.c \
		./rtc/rtc.c \
		./mprintf/mprintf.c \
		./mac/emac.c \
		./mac/EMAC_ISR.c \
		./httpd/httpd.c \
		./httpd/httpd-cgi.c \
		./httpd/httpd-fs.c \
		./httpd/http-strings.c \
		./httpd/uIP_Task.c \
		$(UIPDIR)/uip_arp.c \
		$(UIPDIR)/psock.c \
		$(UIPDIR)/timer.c \
		$(UIPDIR)/uip.c \


ARM_SOURCE= \
				
THUMB_OBJS = $(THUMB_SOURCE:.c=.o)				
ARM_OBJS = $(ARM_SOURCE:.c=.o)

all: ${TARGET}.hex ${TARGET}.lst isp

${TARGET}.bin : ${TARGET}.hex
	$(OBJCOPY) ${TARGET}.elf -O binary ${TARGET}.bin
	 
${TARGET}.hex : ${TARGET}.elf
	$(OBJCOPY) ${TARGET}.elf -O ihex ${TARGET}.hex

${TARGET}.lst : ${TARGET}.elf
	$(OBJDUMP) -h -S -C ${TARGET}.elf > ${TARGET}.lst

${TARGET}.elf :$(ARM_OBJS) $(THUMB_OBJS) boot.s Makefile
	$(CC) $(CFLAGS) $(ARM_OBJS) $(THUMB_OBJS) $(LIBS) boot.s $(LINKER_FLAGS) 

$(ARM_OBJS) : %.o : %.c Makefile
	$(CC) -c $(CFLAGS) $< -o $@

$(THUMB_OBJS) : %.o : %.c Makefile
	$(CC) -c $(CFLAGS) -mthumb $< -o $@

clean :
	rm -f $(ARM_OBJS) $(THUMB_OBJS) ${TARGET}.elf ${TARGET}.hex ${TARGET}.bin ${TARGET}.map ${TARGET}.lst

isp:
	lpc21isp ${TARGET}.hex /dev/ttyUSB0 115200 12000
